package com.shrct.businessprocess.customerservice.impl;

import com.shrct.businessprocess.customerservice.RCContractInstallInfo;
import com.shrct.businessprocess.customerservice.RCProjectMock;
import com.shrct.businessprocess.customerservice.RCProjectReference;
import com.shrct.businessprocess.customerservice.RCRoutineServiceInfo;
import com.shrct.businessprocess.customerservice.RCServiceContractDelegate;
import com.shrct.businessprocess.customerservice.RCServiceContractDelegateDAO;
import com.shrct.businessprocess.customerservice.events.RCServiceContractDelegateEventsManager;
import com.shrct.businessprocess.customerservice.impl.RCContractInstallInfoImpl;
import com.shrct.businessprocess.customerservice.impl.RCProjectMockImpl;
import com.shrct.businessprocess.customerservice.impl.RCProjectReferenceImpl;
import com.shrct.businessprocess.customerservice.impl.RCRoutineServiceInfoImpl;
import com.shrct.businessprocess.organization.RCEnterprise;
import com.shrct.businessprocess.project.RCCustomerContract;
import com.shrct.businessprocess.project.RCProject;
import edu.fudan.mylang.pf.BaseDAOService;
import org.eclipse.xtext.xbase.lib.ObjectExtensions;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service("com.shrct.businessprocess.customerservice.RCServiceContractDelegateDAO")
public class RCServiceContractDelegateDAOImpl extends BaseDAOService<RCServiceContractDelegate> implements RCServiceContractDelegateDAO {
  @Autowired
  private RCServiceContractDelegateEventsManager eventsManager;
  
  public RCProjectMock createAsMockProject(final String projectId, final String contractId, final RCEnterprise customer, final Procedure1<? super RCProjectMock> preCreate) {RCProjectMock rCProjectMock=RCProjectMockImpl.create(getObjectFactory());
    final Procedure1<RCProjectMock> _function = new Procedure1<RCProjectMock>() {
        public void apply(final RCProjectMock it) {
          it.setProjectId(projectId);
          it.setContractId(contractId);
          it.setCustomer(customer);RCContractInstallInfo rCContractInstallInfo=RCContractInstallInfoImpl.create(getObjectFactory());
          it.setInstallInfo(rCContractInstallInfo);RCRoutineServiceInfo rCRoutineServiceInfo=RCRoutineServiceInfoImpl.create(getObjectFactory());
          it.setRoutineServiceInfo(rCRoutineServiceInfo);
          preCreate.apply(it);
          it.start();
          RCServiceContractDelegateDAOImpl.this.eventsManager.fireCreated(it);
        }
      };
    RCProjectMock _doubleArrow = ObjectExtensions.<RCProjectMock>operator_doubleArrow(rCProjectMock, _function);
    return _doubleArrow;
  }
  
  public void deleteProjectReference(final RCProjectReference projectReference) {getObjectFactory().delete(projectReference);
    
  }
  
  public RCProjectReference createAsProjectReference(final RCCustomerContract customerContract, final Procedure1<? super RCProjectReference> preCreate) {RCProjectReference rCProjectReference=RCProjectReferenceImpl.create(getObjectFactory());
    final Procedure1<RCProjectReference> _function = new Procedure1<RCProjectReference>() {
        public void apply(final RCProjectReference it) {
          RCProject _project = customerContract.getProject();
          String _code = _project.getCode();
          it.setProjectId(_code);
          RCEnterprise _customer = customerContract.getCustomer();
          it.setCustomer(_customer);
          RCProject _project_1 = customerContract.getProject();
          String _name = _project_1.getName();
          it.setProjectName(_name);
          String _contractId = customerContract.getContractId();
          it.setContractId(_contractId);RCContractInstallInfo rCContractInstallInfo=RCContractInstallInfoImpl.create(getObjectFactory());
          it.setInstallInfo(rCContractInstallInfo);
          it.setCustomerContract(customerContract);RCRoutineServiceInfo rCRoutineServiceInfo=RCRoutineServiceInfoImpl.create(getObjectFactory());
          it.setRoutineServiceInfo(rCRoutineServiceInfo);
          it.updateBusinessMan();
          it.updateMajorSales();
          preCreate.apply(it);
          it.start();
          RCServiceContractDelegateDAOImpl.this.eventsManager.fireCreated(it);
        }
      };
    RCProjectReference _doubleArrow = ObjectExtensions.<RCProjectReference>operator_doubleArrow(rCProjectReference, _function);
    return _doubleArrow;
  }
}
